// 发送送消息给content
function sendMessageToContentScript(message, callback) {
    chrome.tabs.query({ active: true, currentWindow: true }, function (tabs) {
        chrome.tabs.sendMessage(tabs[0].id, message, function (response) {
            if (callback) callback(response);
        });
    });
}

function chromeMsg(response) {
    // 发送chrome通知
    chrome.notifications.create(null, {
        type: 'basic',
        iconUrl: 'img/logo.png',
        title: '操作通知',
        message: response.message + '\n' + (new Date).toLocaleString()
    });
}

// 开始
$('#start').click(function () {
    sendMessageToContentScript({ cmd: 'start' }, chromeMsg);
});

// 停止
$('#stop').click(function () {
    sendMessageToContentScript({ cmd: 'stop' }, chromeMsg);
});
